package com.litemall.user.service.impl;

import com.litemall.pojo.User;
import com.litemall.response.UserOrderDTO;
import com.litemall.user.api.OrderApi;
import com.litemall.user.mapper.UserMapper;
import com.litemall.user.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : Areli
 * @date : 2020/4/19 21:24
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    OrderApi orderApi;

    @Override
    public User findOne(String username) {
        User user = userMapper.selectByPrimaryKey(username);
        return user;
    }

    @Override
    public List<UserOrderDTO> findUserOrders() {
        String username = "heima";
        List<UserOrderDTO> orderDTOList = orderApi.findUserOrder(username);
        for (UserOrderDTO userOrderDTO : orderDTOList) {
            User user = userMapper.selectByPrimaryKey(userOrderDTO.getUsername());
            BeanUtils.copyProperties(user,userOrderDTO);
        }
        return orderDTOList;
    }
}
